//
//  ZFBFunctionListCell.m
//  支付宝
//
//  Created by HaoYoson on 16/6/28.
//  Copyright © 2016年 HaoYoson. All rights reserved.
//

#import "Masonry.h"
#import "ZFBFunctionListCell.h"

@interface ZFBFunctionListCell ()

@property (weak, nonatomic) UIImageView *iconView;
@property (weak, nonatomic) UILabel *nameLabel;

@end

@implementation ZFBFunctionListCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)awakeFromNib {
    [self setupUI];
}

- (void)setFunction:(ZFBFunction *)function {
    _function = function;

    self.iconView.image = [UIImage imageNamed:function.icon];
    self.nameLabel.text = function.name;
}

- (void)setHighlighted:(BOOL)highlighted {
    [UIView animateWithDuration:.2 animations:^{
        self.backgroundColor = highlighted ? [UIColor colorWithWhite:.9 alpha:1] : [UIColor whiteColor];
    }];
}

- (void)setupUI {
    UIImageView *iconView = [[UIImageView alloc] init];
    iconView.image = [UIImage imageNamed:@"09999976"];
    [self.contentView addSubview:iconView];

    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.font = [UIFont systemFontOfSize:12];
    nameLabel.textColor = [UIColor darkGrayColor];
    nameLabel.text = @"支付吧";
    [self.contentView addSubview:nameLabel];

    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(24);
        make.width.height.offset(24);
        make.centerX.equalTo(self.contentView);
    }];

    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView.mas_bottom).offset(8);
        make.centerX.equalTo(iconView);
    }];

    self.iconView = iconView;
    self.nameLabel = nameLabel;
}
@end
